<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#box{
				background-color: skyblue;
				width: 200px;
				height: 200px;
				opacity: 0.5;
			}
		</style>
	</head>
	<body>
		<div id="box"></div>
	</body>
	<script type="text/javascript">
		window.onload = function(){
			var box = document.getElementById('box')
			box.onmouseover = function(){
				opacityTrans(this,100)
			}
			box.onmouseout = function(){
				opacityTrans(this,30)
			}
			var timer = null,alpha = 30,speed = 0;
			function opacityTrans(obj,endAlpha){
				clearInterval(timer)
				speed = (endAlpha-alpha) / 10;
				timer = setInterval(function(){
					speed = endAlpha > alpha ? 10 : -10;
					if(alpha === endAlpha){
						clearInterval(timer)
						return;
					}
					alpha = alpha + speed;
					box.style.opacity = alpha / 100;
				},30)
				
			}
		}
	</script>
</html>
